<?php 
/**
 * index action
 * @author Yuwei
 *
 */
final class indexAction extends BluePhp_Core_Action
{	
	/**
	 * 数据查询,分页类及模板使用
	 */
	public function index()
	{		
		$model = new userModel();
		$back = $model->select();
		if($back)
		{
			$this->assign('list', $back['list']);
			$this->assign('page', $back['page']);
		}
		$this->display('index/index.html');
	}
	
	/**
	 * 数据新增
	 */
	public function insert()
	{
		$model = new userModel();
		$name = BluePhp_Library_Input_Adapter::get('test');
		$data = array
		(
			'name' => $name
		);
		$back = $model->insert($data);
		var_dump($back);
	}
	
	/**
	 * 数据修改
	 */
	public function update()
	{
		$model = new userModel();
		$data = array
		(
			'name' => 'name'.time()
		);
		$where = 'id = 6';
		$back = $model->update($data,$where);
		var_dump($back);
	}
	
	/**
	 * 数据删除
	 */
	public function delete()
	{
		$model = new userModel();
		$where = 'id = 6';
		$back = $model->delete($where);
		var_dump($back);
	}
	
	/**
	 * session
	 */
	public function session()
	{
		BluePhp_Library_Session_Adapter::set('blue', 'php');
		BluePhp_Library_Session_Adapter::set('blue2', array(1,2,3));
		var_dump($_SESSION);
	}
	
	/**
	 * cookie
	 */
	public function cookie()
	{
		BluePhp_Library_Cookie_Adapter::set('blue', 'php');
		var_dump(BluePhp_Library_Cookie_Adapter::get('blue'));
	}
	
	/**
	 * 缓存
	 */
	public function cache()
	{
		BluePhp_Library_Cache_Adapter::set('key', 'value');
		var_dump(BluePhp_Library_Cache_Adapter::get('key'));
	}
	
	/**
	 * 验证码
	 */
	public function verify()
	{
		BluePhp_Library_Gd_Adapter::verify();
	}
	
	/**
	 * 扩展使用
	 * 
	 * 如果无法下载，请将php.ini中output_buffering设为On
	 */
	public function extention()
	{
		BluePhp_Library_Common_Adapter::includeExtention('PHPExcel'.DIRECTORY_SEPARATOR.'PHPExcel.php');
		
		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();

		// Set document properties
		$objPHPExcel->getProperties()
					->setCreator("Maarten Balliauw")
					->setLastModifiedBy("Maarten Balliauw")
					->setTitle("Office 2007 XLSX Test Document")
					->setSubject("Office 2007 XLSX Test Document")
					->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
					->setKeywords("office 2007 openxml php")
					->setCategory("Test result file");

		// Add some data
		$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A1', 'Hello')
					->setCellValue('B2', 'world!')
					->setCellValue('C1', 'Hello')
					->setCellValue('D2', 'world!');

		// Rename worksheet
		$objPHPExcel->getActiveSheet()->setTitle('BluePhp');

		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);

		// Redirect output to a client’s web browser (Excel2007)
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="BluePhp.xlsx"');
		header('Cache-Control: max-age=0');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
		die();
	}
}
?>